﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CONTROLLER;
using ENTITY;
using DevExpress.XtraEditors;

namespace frm_view
{
    public partial class frmListMonHoc : Form
    {
        EN_MonHoc objMon = new EN_MonHoc();
        ctrls_MonHoc ctr_monHoc = new ctrls_MonHoc();
        /**********************************/
        private void Refesh()
        {
            msds.DataSource = ctr_monHoc.MonHoc_Select_ALL();
        }
        public frmListMonHoc()
        {
            InitializeComponent();
        }

        private void View_MonHoc_Load(object sender, EventArgs e)
        {
              Refesh();
        }

        private void btnLamTuoi_Click(object sender, EventArgs e)
        {
            Refesh();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            objMon.MaMon = gridView1.GetRowCellValue(gridView1.FocusedRowHandle,gridView1.Columns[0]).ToString();
            try
            {
                if (XtraMessageBox.Show("Bạn muốn xóa", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ctr_monHoc.MonHoc_Delete(objMon);
                    XtraMessageBox.Show("Xóa thành công", "Thông báo");
                    Refesh();
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Môn học tồn tại trong Chương", "Fails");
            }
           
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            frmMonHoc frm = new frmMonHoc();
            frm.IsInsert = true;
            frm.LamMoi += new EventHandler(btnLamTuoi_Click);
            frm.ShowDialog();
         
        }

        private void msds_DoubleClick(object sender, EventArgs e)
        {
            frmMonHoc frm = new frmMonHoc();
            frm.ID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0]).ToString();
            frm.IsInsert = false;
            frm.LamMoi += new EventHandler(btnLamTuoi_Click);
            frm.ShowDialog();
        }
        public event EventHandler ThoatForm;
        private void frmListMonHoc_FormClosing(object sender, FormClosingEventArgs e)
        {
            ThoatForm(this,new EventArgs());
        }
    }
}
